package main

import "fmt"

func main() {

	s := []int{1, 2, 3, 4, 5, 6, 7, 8}
	c := make(chan int)
	go sum(s[:len(s)/2], c)
	go sum(s[len(s)/2:], c)
	x, y := <-c, <-c // 从通道 c 中接收
	sum := x + y
	fmt.Println(sum)

}

func sum(s []int, c chan int) {
	sum := 0
	for _, v := range s {
		sum += v
	}
	c <- sum
}
